package org.zgy.stock.service;


import jakarta.annotation.Resource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.info.ProjectInfoAutoConfiguration;
import org.springframework.stereotype.Service;
import org.zgy.stock.dto.StockBaseDto;
import org.zgy.stock.dto.StockPriceDto;
import org.zgy.stock.threads.StockBaseThread;
import org.zgy.stock.utils.RestClientUtils;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.*;

@Service
public class DfcfServiceApiImpl implements DfcfServiceApi {
    @Autowired
    private RestClientUtils restClientUtils;
    @Autowired
    private ProjectInfoAutoConfiguration projectInfoAutoConfiguration;
    @Resource(name = "customTaskExecutor")
    private Executor customTaskExecutor;


    @Override
    public List<StockBaseDto> getStockList() {
        List<StockBaseDto> list = new ArrayList<>();
        try (ExecutorService executor = Executors.newFixedThreadPool(6)) {
            Future<List<StockBaseDto>> future1 = executor.submit(new StockBaseThread(1, 20));
            Future<List<StockBaseDto>> future2 = executor.submit(new StockBaseThread(20, 40));
            Future<List<StockBaseDto>> future3 = executor.submit(new StockBaseThread(40, 60));

            list.addAll(future1.get());
            list.addAll(future2.get());
            list.addAll(future3.get());

        } catch (ExecutionException | InterruptedException e) {
            throw new RuntimeException(e);
        }
        System.out.println(list.size());
        return  list;

    }

    @Override
    public List<StockPriceDto> getStockPriceList() {
        return List.of();
    }
}
